﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace log4netCustomAppenderDemo
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var logCfg = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config");
            log4net.Config.XmlConfigurator.Configure(logCfg);

            ProcessStartInfo processStartInfo = new ProcessStartInfo()
            {
                FileName = "log4net-view.exe",
                Arguments = "WinApiAppenderTest"
            };
            Process p = Process.Start(processStartInfo);
            System.Threading.Thread.Sleep(1000);

            while (true)
            {
                string debug = "这是一条Debug";
                Console.WriteLine(debug);
                log4net.LogManager.GetLogger("firstlevel.DebugLogger").Debug(debug);

                string info = "这是一条Info";
                Console.WriteLine(info);
                log4net.LogManager.GetLogger("firstlevel.InfoLogger").Info(info);

                try
                {
                    string error = "这是一条Error";
                    Console.WriteLine(error);
                    throw new Exception(error);
                }
                catch (Exception ex)
                {
                    log4net.LogManager.GetLogger("secondlevel.ErrorLogger").Error(ex);
                }

                System.Threading.Thread.Sleep(1000);
            }
        }
    }
}
